﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class System_RuleInfo
    {
        public bds m_bds = new bds();
        private DBMain m_data = new DBMain();

        public System_RuleInfo(Guid _iSystem_RuleKey)
        {
            var Iquery = m_data.m_DCSave.System_Rules.Where(p => p.System_RuleKey == _iSystem_RuleKey);
             m_bds.DataSource = Iquery;
             var Row = Iquery.FirstOrDefault();
             if (Row == null)
             {
                 System_Rule sys_Rule = new System_Rule();
                 sys_Rule.System_RuleKey = _iSystem_RuleKey;
                 
                 Row = sys_Rule;
                 m_bds.Add(Row);
                 m_bds.MoveLast();
             }
        }

        public System_RuleInfo(string _strRuleID)
        {
            var Iquery = m_data.m_DCSave.System_Rules.Where(p => p.RuleID == _strRuleID);
            m_bds.DataSource = Iquery;
            var Row = Iquery.FirstOrDefault();
            if (Row == null)
            {
                System_Rule sys_Rule = new System_Rule();
                sys_Rule.System_RuleKey = Guid.NewGuid();
                sys_Rule.RuleID = _strRuleID;
                Row = sys_Rule;
                m_bds.Add(Row);
                m_bds.MoveLast();
            }
        }
        public System_Rule Properties
        {
            get { return m_bds.Current as System_Rule; }
        }

        public void Delete()
        {
            m_bds.DeleteCurrent();
        }

        public void Save()
        {
            m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }
    }
}
